import {
  UserHttp
} from '../../../api/user.js'

const userModel = new UserHttp();

Page({
  initFlag: false,
  data: {
    countData:{
      totalOrderAmount:0,
      totalOrderPriceAmount:0,
      totalCommission:0,
    },
    userInfo: {
      common: {
        pea_rate: 10000,
        pea_blance: 0
      }
    }
  },

  initPage() {
    this.initData();
  },

  onPullDownRefresh: function() {
    this.initData(true)
  },

  onHide() {
    this.initFlag = true;
  },

  onShow() {
    if (this.initFlag === true) {
      this.initFlag = false;
      this.initData();
    }
  },

  initData: function() {
    this.httpGetInviterSum();
  },

  // 获取数据
  httpGetInviterSum() {
    return userModel.inviterSum({
      uid:this.userInfo.uid
    }).then((res) => {
      if (res) {
        this.setData({
          countData: res,
        });
      }else{
        this.setData({
          countData: {
            totalOrderAmount:0,
            totalOrderPriceAmount:0,
            totalCommission:0,
          },
        });
      }
    })
  },
});
